﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using MuaChungDTO;

namespace MuaChungDAO
{
    public class DealDAO : DataProvider
    {
        public DealDAO()
        {

        }
        public ArrayList getDsDeal()
        {
            connect();
            string query = "SELECT * FROM Deal";
            adapter = new SqlDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);

            return arr;
        }


        public ArrayList getDealTheoID(string loaiDealID)/// hoi thua.. can sua lai
        {
            connect();
            string query = "select * from Deal where LoaiDealID = " + loaiDealID ;
            adapter = new SqlDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);

            return arr;
        }

        public ArrayList getDealTheoLoaiID(string loaiDealID)/// hoi thua.. can sua lai
        {
            connect();
            string query = "select * from Deal where LoaiDealID = " + loaiDealID;
            adapter = new SqlDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);

            return arr;
        }

         protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            
            //Deal deal = new Deal();
               DealDTO deal = new DealDTO();
            deal.DealId = int.Parse(dt.Rows[i]["DealId"].ToString());
            deal.DiemNoiBat = dt.Rows[i]["DiemNoiBat"].ToString();
            deal.DieuKien = dt.Rows[i]["DieuKien"].ToString();
            deal.DonGia= int.Parse(dt.Rows[i]["DonGia"].ToString());
            deal.GioiThieu= dt.Rows[i]["GioiThieu"].ToString();
            deal.HinhAnh= dt.Rows[i]["HinhAnh"].ToString();
            deal.LoaiDealId = int.Parse(dt.Rows[i]["LoaiDealId"].ToString());
            deal.MoTa = dt.Rows[i]["MoTa"].ToString();
            deal.SoLuong =int.Parse(dt.Rows[i]["SoLuong"].ToString()) ;
            deal.SoNguoiMuaToiThieu = int.Parse(dt.Rows[i]["SoNguoiMuaToiThieu"].ToString());
            deal.TenDeal = dt.Rows[i]["TenDeal"].ToString();
            deal.TenDoanhNghiep = dt.Rows[i]["TenDoanhNghiep"].ToString();
            deal.ThoiDiemHetHan = DateTime.Parse(dt.Rows[i]["ThoiDiemHetHan"].ToString());
            deal.TietKiem = int.Parse(dt.Rows[i]["TietKiem"].ToString());
            deal.TinhThanhId = int.Parse(dt.Rows[i]["TinhThanhId"].ToString());
            deal.Website = dt.Rows[i]["Website"].ToString();
                               
            return (object)deal;
        }

    }
}
